package de.tu_darmstadt.gdi1.xcom.tests.testcases.tutors;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

import de.tu_darmstadt.gdi1.xcom.tests.adapters.XcomTestAdapterLevel2;

/**
 * 
 * Tests if ammo is in/decreased correctly
 * 
 * @author Lukas Schwoebel
 *
 */
public class AmmoShootingTest {
	
	private XcomTestAdapterLevel2 testAdapter;
	
	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
		testAdapter = new XcomTestAdapterLevel2();
	}
	
	/**
	 * Test method for {@link de.tu_darmstadt.gdi1.xcom.tests.adapters.XcomTestAdapterLevel2#ammoLeft()}.
	 */
	@Test
	public final void testShootingWithZeroAmmo() {
		
		testAdapter.loadLevelFromString(TestLevel.saveGame1.replaceAll("//@;1;4;n;50;75;50;50;10\n", "//@;1;4;e;50;75;50;50;0\n"));
		
		testAdapter.changeActivePlayer(1, 4);
		// walk and turn to alien
		testAdapter.performActionForActivePlayer();
		testAdapter.rotateActivePlayer(false);
		// try to shoot, without ammo
		testAdapter.shoot();
		
		assertEquals("Shooting with 0 ammo should result still in 0 ammo", 0, testAdapter.ammoLeft());
		assertEquals("Shooting with 0 ammo should not change anything, so alien on 2:2 should still be alive", 'Z', testAdapter.elementOnPosition(2, 2));
		assertEquals("Shooting with 0 ammo should not change anything, so alien on 2:2 should still have 50hp", 50, testAdapter.healthPointsOfAlien(2, 2));
		
	}

	/**
	 * Test method for {@link de.tu_darmstadt.gdi1.xcom.tests.adapters.XcomTestAdapterLevel2#ammoLeft()}.
	 */
	@Test
	public final void testShootingWithNoActionpoints() {
		
		testAdapter.loadLevelFromString(TestLevel.testLevel);
		
		// walk to switch and use it (to reduce action points and open door for later implementations)
		testAdapter.rotateActivePlayer(true);
		testAdapter.performActionForActivePlayer();
		testAdapter.rotateActivePlayer(true);
		testAdapter.performActionForActivePlayer();
		testAdapter.performActionForActivePlayer();
		testAdapter.performActionForActivePlayer();
		testAdapter.rotateActivePlayer(false);
		testAdapter.performActionForActivePlayer();
		testAdapter.performActionForActivePlayer();
		testAdapter.performActionForActivePlayer();
		testAdapter.performActionForActivePlayer();
		testAdapter.performActionForActivePlayer();
		testAdapter.rotateActivePlayer(true);
		testAdapter.performActionForActivePlayer();
		testAdapter.rotateActivePlayer(false);
		testAdapter.performActionForActivePlayer();
		testAdapter.performActionForActivePlayer();
		testAdapter.performActionForActivePlayer();
		testAdapter.performActionForActivePlayer();
		testAdapter.performActionForActivePlayer();
		testAdapter.performActionForActivePlayer();
		testAdapter.performActionForActivePlayer();
		testAdapter.performActionForActivePlayer();
		testAdapter.rotateActivePlayer(false);
		testAdapter.rotateActivePlayer(false);
		testAdapter.performActionForActivePlayer();
		testAdapter.performActionForActivePlayer();
		testAdapter.rotateActivePlayer(false);
		testAdapter.rotateActivePlayer(false);
		testAdapter.rotateActivePlayer(false);
		// now user should have 8 actionpoints
		assertEquals("After doing some actions (10 rotations, 19 walking actions, 1 switchusage) the user should have 8 actionpoints left", 8, testAdapter.actionPointsLeft());

		// try to shoot, should cost 10 actionpoints - not possible
		testAdapter.shoot();
		
		assertEquals("Shooting with 8 actionpoints should not be possible, still 8 points should be left afterwards", 8, testAdapter.actionPointsLeft());
		assertEquals("Shooting with 8 actionpoints should not be possible, the alien should still be at 20:4", 'Z', testAdapter.elementOnPosition(20, 4));
		assertEquals("Shooting with 8 actionpoints should not be possible, the alien on 20:4 should still have 50hp", 50, testAdapter.healthPointsOfAlien(20, 4));
		
	}
}
